function countWords(inputText)
{
	// declare and initialize variables
	
	var tokenArray = new Array();		/*	This is an array that will contain string tokens.
											Note that we are using camel case for our variable
											name, as is common in C syntax languages such as
											javascript. */

	var tokenCount = 0;					/*	This is an integer variable that will be used to
											store the count of the number of items in tokenArray.
											I prefer to initialize variables at the time of
											declaration. In a weakly typed language like javascript,
											it helps to make things clearer. */

	tokenArray = inputText.split(" ")	/*	We will split the input string into discrete tokens
											with a space (" ") as the delimiter. These tokens
											are placed in the array. */
											


	tokenCount = tokenArray.length		/*	Set tokenCount equal to the length (number of items in)
											the array. */

											
	return tokenCount;					/*	Returns the value of tokenCount to the function caller */

}

/*	This is the text we will pass into the function above to be counted. Change it to whatever you want, 
	but be careful to avoid putting quotation marks inside the text until you understand the concept of
	escaping */
	
var textBody = "The quick brown fox jumped over the lazy red dog.";

/* Call the wordCount function and pass in textBody to be counted. */

var wordCount = countWords(textBody);

/*	Convert the results from a number to a string and echo it out to a dialog box. The WScript object is
	part of Microsoft's JScript host environment. If you were embedding this script in a web page, for example,
	you would use window.alert() instead. */

WScript.Echo("Your test string has " + wordCount.toString() + " words.");
